function getBoxList() {
    let boxList = {};
    $.ajax({
        async: false,
        type: "post",//type可以为post也可以为get
        url: "http://localhost:3000/employments",
        dataType: "json",//这里要注意如果后台返回的数据不是json格式，那么就会进入到error:function(data){}中
        success: function (data) {
            // console.log(data)
            // boxList=data;
            boxList = data
            // alert(data)
        },
        error: function (data) {
        }
    });
    return boxList;
}

let data = getBoxList();
console.log(data)


let btn = document.getElementsByClassName("btn");
btn[4].style.backgroundColor = "#FE6C00";

document.getElementsByClassName("bgm")[0].innerHTML = `
    <img src="./assets//img/employment.png">
    `;
let box = document.getElementsByClassName("quesForm")[0];
let button = document.getElementsByClassName("button")[0];
box.style.display = "none";
button.onclick = () => {
    // console.log(this)
    // box.style.display="block?none:block"
    if (box.style.display === "none") {
        box.style.display = "block"
    }
}
let form = {title: "", content: "", eye: "0", news: "0"};
// 提问----------------------------------------------
$("#submitBtn").on("click", function () {
    form.title = $("#tit").val();
    form.content = $("#con").val();
    if (form.title.trim().length == 0) {
        alert('请输入标题')
        return;
    }
    if (form.content.trim().length == 0) {
        alert('请输入内容')
        return;
    }
    console.log(form)
    $.ajax({
        type: "post",
        url: "http://localhost:3000/employments",
        data: JSON.stringify(form),
        contentType: "application/json",
        success: function (res) {
            console.log(res)

        },
        error: function (res) {
            console.log("sbai")
        }

    })
})


// 你问我答--------------------------------------------
let submitLeft = document.getElementsByClassName("submitLeft")[0]
submitLeft.onclick = () => {
    box.style.display = "none";
}

document.getElementsByClassName("comment")[0].innerHTML = getComment(data.commentList);

function getComment(data) {
    let list = ``;
    data.forEach(function (item, index) {
        list += `
<div class="commentList">
    <div class="commentListTitle">
    <div class="commentListTitleBorder"></div>
    <div class="commentListTitleDetail">${item.title}</div>
    </div>
    <span class="commentListContent">${item.content}</span>
<div class="view">
    <div class="info"><i class="iconfont icon-xinxi"></i><span class="h1">${item.eye}</span></div>
<div class="eye"><i class="iconfont icon-yanjing"></i><span class="h2">${item.news}</span></div>

</div>
</div>`
    })
    return list;
}


// 职场冲浪---------------------------------------


document.getElementsByClassName('policy')[0].innerHTML = getSupportList(data.policy);

function getSupportList(data) {
    let supportList = ``;
    data.forEach(function (item, i) {
        if (i < 4) {
            supportList += `
            <div class="policyListItem">
                <div class="policyListItemImg"><img src='${item.imgSrc}'></div>
                 <div class="policyContent">
                   <div class="policyTitle">${item.title}</div>
                        <div class="policyDetail">${item.content}</div>
                        <div>
                        <span class="policyAuthor">作者：${item.author}</span>
                        <span class="policyAuthor">时间：${item.date}</span>
                        </div>
                </div>
            </div>
            `
        }
    });
    return supportList;
};
